/**用户登录 */
$("header>div>a").click(function(){
    $("pre").show();
})
$("pre>a").click(function(){
    $("pre").hide();
})
$("pre>input:eq(2)").click(function(){console.log($("#password").val()=="");
    if($("#username").val()==""||$("#password").val()==""){
        alert("用户名或密码不能为空");
    }else{
        $.ajax({
            type:"POST",
            url:"http://www.coolneng.com/form/",
            data:{userName:$("#username").val(),password:$("#password").val()},
            success:function(res){
                var a=JSON.parse(res);
                $("header>div>a").html("<img src="+a.pic+">"+a.content.userName);
                $("header>div>a").removeClass("fa fa-user-circle-o");
            }
        });
        $("pre").hide();
    }
})
/* 用户评论 */
$("#talkmsg>input").click(function(){console.log($("header>div>a").text());
    if($("header>div>a").text()=='登陆'){
        alert('未登录不能评论');
    }else{    
        $("#talklist").show();
    }
})
$("#talklist a").click(function(){
    $("#talklist").hide();
})
$("#talklist>input").click(function(){
        $.ajax({
            type:"POST",
            url:"http://www.coolneng.com/form/",
            data:{text:$("textarea").val()},
            success:function(res){
                console.log(res);
                var a=JSON.parse(res);
                $("#talkmsg>div").append("<img src='"+$("header>div>a>img")[0].src+"'><p class='tp0'>"+$("header>div>a").text()+"："+a.content.text+"</p><p class='tpl'>"+a.date+"</p><hr>");
            }
        });
        $("#talklist").hide();
})
/**皮肤转换 */
var colors;
$("#pf").on("input",function(){
    colors=$(this).val();
    //console.log(colors)
    pf();
})
function pf(){
    $("header").css("background",colors);
    $("footer").css("background",colors);
    $("#musiclist1").css("border-color",colors);
}
/**播放方式 */
var playstyle=0;
$("#playstyle").click(function(){
    if(playstyle==0){
        $(this).removeClass("fa fa-random");
        $(this).addClass("fa fa-refresh");
        playstyle=1;
    }else if(playstyle==1){
        $(this).removeClass("fa fa-refresh");    // fa fa-refresh    fa fa-random
        $(this).addClass("fa fa-random");
        playstyle=0;
    }
    
})
$("audio").on("ended",function(){
    if(playstyle==0){
        activeNum=Math.floor(Math.random()*2);
        console.log(activeNum);
        $("audio")[0].src=data[activeNum].url;
        $("#play").removeClass("fa fa-play-circle fa-2x play");
        $("#play").addClass("fa fa-pause-circle fa-2x play");
        clacTime();
        $("#sj2").html(showTime());
        $("#musiclist").html("");
        startMusic();
        $("audio")[0].play();
    }else if(playstyle==1){
        ++activeNum==data.length&&(activeNum=0);
        $("#play").removeClass("fa fa-play-circle fa-2x play");
        $("#play").addClass("fa fa-pause-circle fa-2x play");
        clacTime();
        $("#sj2").html(showTime());
        $("#musiclist").html("");
        $("audio")[0].src=data[activeNum].url;
        startMusic();
        $("audio")[0].play();
    }
})
/**播放列表 */
$("#list1").click(function(){
    if($("#musiclist1").is(":hidden")){
        $("#musiclist1").show();
    }else{
        $("#musiclist1").hide();
    }
})
$("#musiclist1>ul li").click(function(){//播放列表歌曲转换
    activeNum=$(this)[0].id;
    $("#play").removeClass("fa fa-play-circle fa-2x play");
    $("#play").addClass("fa fa-pause-circle fa-2x play");
    clacTime();
    $("#sj2").html(showTime());
    $("#musiclist").html("");
    $("audio")[0].src=data[activeNum].url;
    startMusic();
    $("audio")[0].play();
})
/*播放和暂停*/
$("#play").click(function(){
    if($("audio")[0].paused){
        $("audio")[0].play();
        $("#play").removeClass("fa fa-play-circle fa-2x play");
        $("#play").addClass("fa fa-pause-circle fa-2x play");
        $("#rg1")[0].max=$("audio")[0].duration;
        $("#sj2").html(showTime());
        clacTime();
        startMusic();
    }else{
        $("audio")[0].pause();
        $("#play").removeClass("fa fa-pause-circle fa-2x play");
        $("#play").addClass("fa fa-play-circle fa-2x play");
        clearTimeout(t)
    }
})
/**初始加载 */
$(function(){
    clacTime();
    startMusic();
    clearTimeout(t)
})
/* 歌曲进度条绑定播放时间 */
function chooseMusic(){
    $("audio")[0].currentTime=$("#rg1").val();
    if($("#rg1").val()=='0'){
		//拖动进度条播放键的状态
        $("#play").removeClass("fa fa-pause-circle fa-2x play");
        $("#play").addClass("fa fa-play-circle fa-2x play");
    }else{
        $("#play").removeClass("fa fa-play-circle fa-2x play");
        $("#play").addClass("fa fa-pause-circle fa-2x play");
    }
}
$("audio").on("timeupdate",function(){
    $("#rg1").val($("audio")[0].currentTime);
    $("#sj1").val(b=$("audio")[0].currentTime.toFixed(0));
})
$("audio")[0].oncanplay=function(){
    a=$("audio")[0].duration.toFixed(0);
    showTime();
}
var a;
function showTime(){
    var c=Number(a);//console.log(a);
    $("#rg1")[0].max=c;
    if(c>60){
        if(c%60<10){
            $("#sj2").html("0"+c/60+":0"+c%60);
        }else{
            $("#sj2").html("0"+(c/60).toFixed(0)+":"+c%60);
        }
    }else{
        if(c<10){
            $("#sj2").html("00:0"+c);
        }else{
            $("#sj2").html("00:"+c);
        }
    }
}
var b=0,t;//计数器
function clacTime(){
    var a=Number($("audio")[0].duration.toFixed(0));
    if(b<a){
        b++;
        if(b>60){
            if(b%60<10){
                $("#sj1").html("0"+(b/60).toFixed(0)+":0"+b%60);
            }else{
                $("#sj1").html("0"+(b/60).toFixed(0)+":"+b%60);
            }
        }else{
            if(b<10){
                $("#sj1").html("00:0"+b);
            }else{
                $("#sj1").html("00:"+b);
            }
        }
    }
    t=setTimeout(clacTime,1000);
    if(b>a+1){
        clearTimeout(t);
    }
}
/**下一曲 */
$("#next").click(function(){console.log(activeNum);
    ++activeNum==data.length&&(activeNum=0);
    $("#musiclist").html("");
    if($("audio")[0].paused){  
    }else{
        $("audio")[0].src=data[activeNum].url;
        startMusic();
        $("audio")[0].play();
    }
})
$("#Previous").click(function(){console.log(activeNum);
    activeNum==0&&(activeNum=data.length);
    activeNum--;
    $("#musiclist").html("");
    if($("audio")[0].paused){
        
    }else{
        $("audio")[0].src=data[activeNum].url;
        startMusic();
        $("audio")[0].play();
    }
})
/* 音量 */
$("#sound").click(function(){
    if($("#rg2").val()=='0.2'){
        $("#rg2").val(0);
    }else{
        $("#rg2").val(0.2);
    }
    chooseVolume();
})
function chooseVolume(){
    $("audio")[0].volume=$("#rg2").val();
    if($("#rg2").val()=='0'){
        $("#sound").removeClass("fa fa-bell-o fa-lg");
        $("#sound").addClass("fa fa-bell-slash-o fa-lg");
    }else{
        $("#sound").removeClass("fa fa-bell-slash-o fa-lg");
        $("#sound").addClass("fa fa-bell-o fa-lg");
    }
}
/*歌曲信息，歌曲评论*/
 var data=[
    {
        "id":"0","song": "你不在","album": "你不在","singer": "魏恩佳","source": "搜索页","url": "music/nbz.mp3",
        "lyric": "nbz","cover": "http://img.5nd.com/photo/2019album/20194/91297.jpg", "love": "0",
        "msg": [
            {"megId":"img/1.jpg","megCon":"我单身许多年","date":"2018-08-01 14:36:02","userId":"1"},
            {"megId":"img/2.jpg","megCon":"下网易云，就是为了听西彬的完整版","date":"2018-08-11 08:10:05","userId":"2"}
        ]
    },
    {
        "id":"1","song": "生来倔强","album": "生来倔强","singer": "南征北战NZBZ","source": "搜索页","url": "music/sljj.mp3",
        "lyric": "sljj","cover": "https://dss2.bdstatic.com/6Ot1bjeh1BF3odCf/it/u=3202001588,3454933131&fm=74&app=80&f=JPG&size=f121,121?sec=1880279984&t=54ba02057bafbbe69ef108735b8eab24", "love": "0",
        "msg": [
            {"megId":"img/2.jpg","megCon":"与乞丐谋早餐","date":"2018-08-01 14:36:02","userId":"1"},
             {"megId":"img/1.jpg","megCon":"下网易云，就是为了听西彬的完整版","date":"2018-08-11 08:10:05","userId":"2"}
        ]
    },
    {
        "id":"2","song": "是风动","album": "蚍蜉渡海","singer": "银临","source": "搜索页","url": "music/sfd.mp3",
        "lyric": "sfd","cover": "https://dss2.baidu.com/6ONYsjip0QIZ8tyhnq/it/u=253982378,1246093373&fm=85&app=63&f=JPEG?w=121&h=75&s=09295F32CF0A674D5AF565DA0300A0B1", "love": "0",
        "msg": [
            {"megId":"img/1.jpg","megCon":"追了我两三天……","date":"2018-08-01 14:36:02","userId":"1"},
            {"megId":"img/2.jpg","megCon":"下网易云，就是为了听西彬的完整版","date":"2018-08-11 08:10:05","userId":"2"}
        ]
    }
]
/*歌词对象*/
 var lrcs = [
    {"song":"nbz","lyric":[{"time":1,"lineLyric":"编曲：BIN"},{"time":2,"lineLyric":"这空荡的房间 残留你的气味"},{"time":7,"lineLyric":"这孤独的氛围 我早就体会"},{"time":11,"lineLyric":"我已习惯晚睡 习惯自我安慰"},{"time":15,"lineLyric":"闭上眼你出现 没有一点防备"},{"time":19,"lineLyric":"我拥有你 却不仅仅 只限于我自己"},{"time":22,"lineLyric":"你属于我 更属于你 这爱的独角戏"},{"time":29,"lineLyric":"好奇你是否像我一样"},{"time":33,"lineLyric":"不顾一切去你身旁"},{"time":34,"lineLyric":"I miss you but you always not around"},{"time":38,"lineLyric":"像鱼离开水就会缺氧"},{"time":42,"lineLyric":"这一刻心却无处安放"},{"time":46,"lineLyric":"You're not around， you‘re not around babe"},{"time":52,"lineLyric":"I woke up at 3 in the morning"},{"time":56,"lineLyric":"Wish you were here with me，like 123"},{"time":60,"lineLyric":"想要的不只是你在这里"},{"time":64,"lineLyric":"陪我听雨滴 看完所有风景"},{"time":68,"lineLyric":"我拥有你 却不仅仅 只限于我自己"},{"time":72,"lineLyric":"你属于我 更属于你 这爱的独角戏"},{"time":77,"lineLyric":"（oh babe babe ）好奇你是否像我一样"},{"time":81,"lineLyric":"（oh babe babe ）不顾一切去你身旁"},{"time":84,"lineLyric":"I miss you but you always not around"},{"time":88,"lineLyric":"像鱼离开水就会缺氧"},{"time":92,"lineLyric":"这一刻心却无处安放"},{"time":96,"lineLyric":"You're not around， you‘re not around babe"},{"time":133,"lineLyric":"I miss you but you always not around"},{"time":137,"lineLyric":"像鱼离开水就会缺氧"},{"time":141,"lineLyric":"这一刻心却无处安放"},{"time":145,"lineLyric":"You're not around， you‘re not around babe"},{"time":160,"lineLyric":"混音/母带：壹leven (Seer Music)"},{"time":161,"lineLyric":"和声设计：EnjiA魏恩佳"},{"time":162,"lineLyric":"录音室：GVO對音乐"},{"time":163,"lineLyric":"制作/出品：GVO對音乐"}]}   
    ,{"song":"sljj","lyric":[{"time":5,"lineLyric":"编曲：南征北战"},{"time":7,"lineLyric":""},{"time":18,"lineLyric":"有一种力量无人能抵挡"},{"time":24,"lineLyric":"它永不言败生来倔强"},{"time":29,"lineLyric":"有一种理想照亮了迷茫"},{"time":34,"lineLyric":"在那写满荣耀的地方"},{"time":38,"lineLyric":""},{"time":39,"lineLyric":"当那熟悉的旋律响起"},{"time":41,"lineLyric":"昂首挺胸"},{"time":42,"lineLyric":"仰望那鲜艳的旗帜扬起"},{"time":44,"lineLyric":"灾难降临时你我患难与共"},{"time":47,"lineLyric":"互助 关爱 绝不无动于衷"},{"time":49,"lineLyric":"与真相对白"},{"time":50,"lineLyric":"正视历史勇敢面对未来"},{"time":52,"lineLyric":"期盼着英雄们平安地归来"},{"time":53,"lineLyric":"从不妥协 大国尊严不容侵犯"},{"time":56,"lineLyric":"永不让步 每寸领土不容侵占"},{"time":58,"lineLyric":"我不再是从前那饱受欺辱的模样"},{"time":61,"lineLyric":"坚毅的心和脚步没有谁能够阻挡"},{"time":63,"lineLyric":"我不在乎别人是否对我嘲笑"},{"time":66,"lineLyric":"尽管曾经我也是那样的渺小"},{"time":68,"lineLyric":"乘风破浪就像踏步在长征的路上"},{"time":70,"lineLyric":"誓言捍卫这片大地利剑般的目光"},{"time":73,"lineLyric":"我为我的祖国而感到骄傲"},{"time":75,"lineLyric":"就让五星红旗自由地飘"},{"time":77,"lineLyric":"有一种力量无人能抵挡"},{"time":82,"lineLyric":"它永不言败生来倔强"},{"time":86,"lineLyric":""},{"time":87,"lineLyric":"有一种理想照亮了迷茫"},{"time":92,"lineLyric":"在我深感自豪的地方"},{"time":97,"lineLyric":""},{"time":98,"lineLyric":"因为我是这个国家的青年"},{"time":100,"lineLyric":"坚信着都有一个共同的心愿"},{"time":102,"lineLyric":"经历了贫穷和落后也曾一无所有"},{"time":104,"lineLyric":"义无反顾无论水有多深山有多陡"},{"time":107,"lineLyric":""},{"time":107,"lineLyric":"逆境中站起 走过谦卑的路途"},{"time":110,"lineLyric":"热情被唤起 铭记先辈的付出"},{"time":111,"lineLyric":""},{"time":112,"lineLyric":"不要冷漠着 肩并肩负重前行"},{"time":114,"lineLyric":"不必沉默了"},{"time":115,"lineLyric":"放声歌唱把你我的脊梁坚挺"},{"time":116,"lineLyric":"经过了多年的磨炼 告别了昨天"},{"time":118,"lineLyric":"挣开了锁链 凝聚了火焰"},{"time":119,"lineLyric":"钢筋和铁骨刷新着纪录"},{"time":120,"lineLyric":"勤劳和善良是我为人的艺术"},{"time":121,"lineLyric":"冰天雪地里练就了一身本领"},{"time":123,"lineLyric":"把不可能的变成了可能"},{"time":124,"lineLyric":"推开世界的门 只要每个人"},{"time":125,"lineLyric":"肩负使命担当着各自的责任"},{"time":127,"lineLyric":"乘风破浪就像踏步在长征的路上"},{"time":129,"lineLyric":"誓言捍卫这片大地利剑般的目光"},{"time":131,"lineLyric":"我为我的祖国而感到骄傲"},{"time":133,"lineLyric":"就让五星红旗自由地飘"},{"time":136,"lineLyric":"有一种力量无人能抵挡"},{"time":140,"lineLyric":""},{"time":140,"lineLyric":"它永不言败生来倔强"},{"time":144,"lineLyric":""},{"time":145,"lineLyric":"有一种理想照亮了迷茫"},{"time":150,"lineLyric":"在那写满荣耀的地方"},{"time":154,"lineLyric":""},{"time":174,"lineLyric":"有一种力量无人能抵挡"},{"time":178,"lineLyric":""},{"time":179,"lineLyric":"它永不言败生来倔强"},{"time":183,"lineLyric":""},{"time":183,"lineLyric":"有一种理想照亮了迷茫"},{"time":188,"lineLyric":""},{"time":189,"lineLyric":"在我深感自豪的地方"},{"time":193,"lineLyric":"有一种力量无人能抵挡"},{"time":198,"lineLyric":""},{"time":199,"lineLyric":"它永不言败生来倔强"},{"time":202,"lineLyric":""},{"time":203,"lineLyric":"有一种理想照亮了迷茫"},{"time":207,"lineLyric":""},{"time":208,"lineLyric":"在那写满荣耀的地方"}]}
    ,{"song":"sfd","lyric":[{"time":12,"lineLyric":"编曲/混音：灰原穷"},{"time":12,"lineLyric":"母带：周天澈"},{"time":14,"lineLyric":"电吉他：Tanjoy"},{"time":14,"lineLyric":"小提琴：武奥列 李宜珊"},{"time":36,"lineLyric":"若非万种飞烟都过眼，"},{"time":42,"lineLyric":"怎会迷恋巫山的那一片；"},{"time":48,"lineLyric":"若非海枯石烂相看两相厌，"},{"time":54,"lineLyric":"怎又会弱水涨桑田。"},{"time":60,"lineLyric":"以为衔泥归来旧堂前，"},{"time":66,"lineLyric":"是我似曾相识的那一面；"},{"time":72,"lineLyric":"以为积雪成川有孤鸿不知疲倦，"},{"time":78,"lineLyric":"印下你岁月的足尖。"},{"time":83,"lineLyric":"聚似飞霜不肯融，散如尘埃各西东，"},{"time":88,"lineLyric":"痴人说着梦，都道情之所钟。"},{"time":95,"lineLyric":"求不得就偏宠，心猿意马就相拥，"},{"time":100,"lineLyric":"是风动，还是幡动，轮回难道就不同。"},{"time":106,"lineLyric":"你是我身外，化白云任去来，"},{"time":112,"lineLyric":"推开孤城万里，吹渡春风几千载，"},{"time":118,"lineLyric":"我是你途中，有青山撞入怀，"},{"time":124,"lineLyric":"不动声色见你如是才自在。"},{"time":155,"lineLyric":"难道逆水行舟的执念，"},{"time":160,"lineLyric":"是你刻在船舷的那一剑；"},{"time":167,"lineLyric":"难道临渊而羡又纷纷得鱼忘筌，"},{"time":172,"lineLyric":"也值我缘木求此愿？"},{"time":178,"lineLyric":"聚似飞霜不肯融，散如尘埃各西东，"},{"time":183,"lineLyric":"痴人说着梦，都道情之所钟。"},{"time":189,"lineLyric":"求不得就偏宠，心猿意马就相拥，"},{"time":195,"lineLyric":"是风动，还是幡动，轮回难道就不同。"},{"time":201,"lineLyric":"你是我身外，化白云任去来，"},{"time":207,"lineLyric":"推开孤城万里，吹渡春风几千载，"},{"time":213,"lineLyric":"我是你途中，有青山撞入怀，"},{"time":219,"lineLyric":"不动声色见你如是才自在。"},{"time":225,"lineLyric":"你在我身畔，听竹林正摇乱，"},{"time":230,"lineLyric":"侵如野火纷燃，震如千军雷声绽，"},{"time":236,"lineLyric":"我在你此岸，立风雨安如山，"},{"time":243,"lineLyric":"不动于心见你如是才无憾。"},{"time":248,"lineLyric":"啦啦啦~"}]}
];
//  音乐开始时，需要做的几件事情
var activeNum=0;
function startMusic(){
    $(".left>img").attr("src",data[activeNum].cover);
    getLrc();
    getMsg();
}
function getMsg(){
    $("#talkmsg>div").html("");
    for(var i=0;i<data[activeNum].msg.length;i++){
        $("#talkmsg>div").append("<img src='"+data[activeNum].msg[i].megId+"'><p class='tp0'>"+data[activeNum].msg[i].userId+"："+data[activeNum].msg[i].megCon+"</p><p class='tpl'>"+data[activeNum].msg[i].date+"</p><hr>");
    }
}
//    获取歌词
function getLrc(){
    $(".right h1").html(data[activeNum].song);
    $(".right b:eq(0) a").html(data[activeNum].album);
    $(".right b:eq(1) a").html(data[activeNum].singer);
    $(".right>div").html("");
    for(var i=0;i<lrcs.length;i++){
        if(data[activeNum].lyric==lrcs[i].song){
            for(var j=0;j<lrcs[i].lyric.length;j++){
                $(".right>div").append("<p data-time='"+lrcs[i].lyric[j].time+"'>"+lrcs[i].lyric[j].lineLyric+"</p>");
            }
        }
    }
}
/* 桌面歌词 */
$("#desktoplrc").click(function(){
    if($('#musiclist').is(":hidden")){
        $("#desktoplrc").removeClass("fa fa-toggle-off");
        $("#desktoplrc").addClass("fa fa-toggle-on");
        $('#musiclist').show();
    }else{
        $("#desktoplrc").removeClass("fa fa-toggle-on");
        $("#desktoplrc").addClass("fa fa-toggle-off");
        $('#musiclist').hide();
    }
})
$("audio").on("timeupdate",function(){
    for(var i=0;i<$(".right>div p").length;i++){
        if(Math.ceil($("audio")[0].currentTime)>$(".right>div p:eq("+i+")").attr("data-time")){
            $(".right>div p:eq("+i+")").css("color","white");
            $(".right>div p:eq("+(i-1)+")").css("color","black");
            $(".right>div").scrollTop(35*i-70);//更改为35 ，稳定滚动到最后
            $("#musiclist").html($(".right>div p:eq("+i+")").html());
        }
    }
})